home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / OpenGL 1.0 SDK / Source / Libraries / glut / glut_util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  2.1 KB  |  95 lines  |  [TEXT/CWIE]

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1994. */
  3.  
  4. /* This program is freely distributable without licensing fees
  5.    and is provided without guarantee or warrantee expressed or
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. #include <stdlib.h>
  9. #include <stdarg.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. #include "glut.h"
  14. #include "glutint.h"
  15.  
  16. #define PRINT_LOG_FILE_NAME   "glut_error_log"
  17.  
  18. static FILE *__glutLogFile = NULL;
  19.  
  20. void __glutCToPStr(const char *cs, Str255 ps)
  21. {
  22.     GLint i, l;
  23.     
  24.     l = strlen(cs);
  25.     if(l > 255) l = 255;
  26.     ps[0] = l;
  27.     for(i = 0; i < l; i++) ps[i + 1] = cs[i];
  28. }
  29.  
  30. void glutReportErrors(void)
  31. {
  32.     GLenum error;
  33.  
  34.     while ((error = glGetError()) != GL_NO_ERROR)
  35.         __glutWarning("GL error: %s", gluErrorString(error));
  36. }
  37.  
  38. void __glutWarning(const char *format,...)
  39. {
  40.   va_list args;
  41.   
  42.   if(__glutLogFile == NULL) __glutLogFile = fopen(PRINT_LOG_FILE_NAME, "w");
  43.   if(__glutLogFile == NULL) return;
  44.  
  45.   va_start(args, format);
  46.   fprintf(__glutLogFile, "GLUT: Warning in %s: ",
  47.     __glutProgramName ? __glutProgramName : "(unamed)");
  48.   vfprintf(__glutLogFile, format, args);
  49.   va_end(args);
  50.   fprintf(__glutLogFile, "\n");
  51. }
  52.  
  53. void __glutFatalError(const char *format,...)
  54. {
  55.   va_list args;
  56.  
  57.   if(__glutLogFile == NULL) __glutLogFile = fopen(PRINT_LOG_FILE_NAME, "w");
  58.   if(__glutLogFile == NULL) return;
  59.   
  60.   va_start(args, format);
  61.   fprintf(__glutLogFile, "GLUT: Fatal Error in %s: ",
  62.     __glutProgramName ? __glutProgramName : "(unamed)");
  63.   vfprintf(__glutLogFile, format, args);
  64.   va_end(args);
  65.   fprintf(__glutLogFile, "\n");
  66.   exit(1);
  67. }
  68.  
  69. void __glutFatalUsage(const char *format,...)
  70. {
  71.   va_list args;
  72.  
  73.   if(__glutLogFile == NULL) __glutLogFile = fopen(PRINT_LOG_FILE_NAME, "w");
  74.   if(__glutLogFile == NULL) return;
  75.   
  76.   va_start(args, format);
  77.   fprintf(__glutLogFile, "GLUT: Fatal API Usage in %s: ",
  78.     __glutProgramName ? __glutProgramName : "(unamed)");
  79.   vfprintf(__glutLogFile, format, args);
  80.   va_end(args);
  81.   fprintf(__glutLogFile, "\n");
  82.   abort();
  83. }
  84.  
  85. char *
  86. __glutStrdup(const char *string)
  87. {
  88.   char *copy;
  89.  
  90.   copy = malloc(strlen(string) + 1);
  91.   if (copy == NULL)
  92.     return NULL;
  93.   strcpy(copy, string);
  94.   return copy;
  95. }